home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4719 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: apm-b325-8.ucsd.edu!user
  2. From: bredelin@sdcc13.ucsd.edu (Benjamin Redelings)
  3. Newsgroups: comp.lang.c++
  4. Subject: Asynchronous I/O, Re: cin.get() function challenge
  5. Date: 31 Jan 1996 21:14:00 GMT
  6. Organization: University of California, San Diego
  7. Message-ID: <bredelin-3101961313580001@apm-b325-8.ucsd.edu>
  8. References: <4eavds$d0u@news.cencom.net> <ALUN.CHAMPION.96Jan29143951@g7240065.bridge.bst.bls.com>
  9. NNTP-Posting-Host: apm-b325-8.ucsd.edu
  10.  
  11. I've been trying to find a read routine that doesn't block (i.e. wait to
  12. return) until a carriage return is entered.  My program needs to
  13. continuously process data, stopping periodically to process any input that
  14. may have enterred the keyboard buffers since that last time it checked.
  15.  
  16.  
  17. A. On method would be the check the size of the keyboard buffer, called
  18. cin.get() only if a complete line is present.  That would be optimal, and
  19. would not involve any blocking.  However, whoever wrote iostream went to
  20. great lengths to make sure that checking the size of cin's buffer is
  21. really nasty.  I think I would have to write my own io library just to
  22. check the size of the keyboard buffer!
  23.  
  24. B. The other method would be to read all the input that is available, and
  25. process if necessary.  However, if there is NO input, cin.get() WAITS for
  26. a carriage return, which means that the user must press return every time
  27. cin.get() is called to make the program keep processing.  That is
  28. ridiculous.
  29.  
  30. However, Alun Champion says
  31. > It is the host environment which line buffers.  
  32. > In the UNIX environment you can use ioctl() calls to change the
  33. > buffering characteristics of the terminal attached to cin, in other
  34. > environments there may or may not be a mechanism by which you can
  35. > inform the environment that line buffering is not to be performed.
  36. > This is very dependent on the host environment, try a programmers
  37. > newsgroup for the environment you are interested in.
  38.  
  39. Does anyone have more information?  How does one go about this, and what
  40. might cin.get() be expected to return if it underflowed?
  41.  
  42. Thanks,
  43. BenRI
  44.